﻿using System;

using zijian666.Converts.Abstractions;
using zijian666.Converts.Core;

namespace zijian666.Converts.Convertor.Base;

/// <summary>
/// 允许 将 null 或 <seealso cref="DBNull.Value"/> 值的转换器
/// </summary>
public abstract class AllowNullConvertor<T> : FromConvertor<T>, IFromNull<T>
{
    /// <summary>
    /// 将 null 转换为指定类型
    /// </summary>
    public ConvertResult<T> FromNull(IConvertContext context) => default(T);

    /// <summary>
    /// 将 <seealso cref="DBNull.Value"/> 转换指定类型
    /// </summary>
    /// <param name="context"></param>
    /// <param name="input"></param>
    /// <returns></returns>
    public ConvertResult<T> From(IConvertContext context, DBNull? input) => default(T);
}
